<%@ page language="java" import="java.sql.*" contentType="text/html;charset=UTF-8" %>
<%/*@ page language="java" import="java.sql.*" contentType="text/html;charset=KSC5601" */%>

<%	
 	String sName = request.getParameter("name");
    String sEmail = request.getParameter("email");
    String sTitle = request.getParameter("title");
    String sContent = request.getParameter("content");
    String sPwd = request.getParameter("pwd");
    int intIdx = Integer.parseInt(request.getParameter("idx"));
    
    String DB_URL = "jdbc:mysql://localhost:3306/bbs?useUnicode=true&characterEncoding=utf8";
    String DB_USER = "root";
    String DB_PASSWORD = "root";
    
    Statement stmt;    
    String query1="SELECT PASSWORD FROM GUEST WHERE IDX='"+intIdx+"'"; 
    String query2 = "UPDATE GUEST SET NAME='"+sName+"',EMAIL='"+sEmail+"',TITLE='"+sTitle+"',CONTENT='"+sContent+"',PASSWORD='"+sPwd+"' WHERE IDX="+intIdx+""; 
	
	try {
		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
		stmt = conn.createStatement();
		ResultSet result = null;
		
		result = stmt.executeQuery(query1);
		if(result.next()){
			if(sPwd.equals(result.getString(1))){
				stmt.executeUpdate(query2);
				result.close();
				stmt.close();
				conn.close();
				response.sendRedirect("list.jsp");
			}
			result.close();
		}
		stmt.close();
		conn.close();
 
%>		
 <!-- <body onload="locaction.href='modify.jsp?idx=<%=intIdx%>'"> -->
	<body onLoad="location.href='javascript:history.go(-1)'"><!-- 여기 -->

<%	
	}catch(Exception e){e.printStackTrace();}
%>
